<?php 
	header("content-type:text/html;charset=utf-8");
	$pdo = new PDO("mysql:host=127.0.0.1;dbname=lianxi;charset=utf8","root","root");
	$redis = new Redis();
	$redis->connect("127.0.0.1","6379");
	$page = isset($_GET['page'])?$_GET['page'] : 1;
	$sql = "select count(*) from `fenye`";
	$res = $pdo->query($sql)->fetch();
	$pagenum = $res['count(*)'];
	$pagesize = 3;
	$totalpage = ceil($pagenum/$pagesize);
	$limit = ($page-1)*$pagesize;
	if($redis->get("data".$page)){
		echo "这是redis中的数据";
		$data= $redis->get("data".$page);
		$data = json_decode($data,true);
	}else{
		$sql = "select * from `fenye` limit $limit,$pagesize";
		$data = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
		$redisdata = json_decode($data);
		$redis->set("data".$page,$redisdata);
	}
	$pre = $page-1>0 ? $page-1:1;
	$next = $page+1>$totalpage ? $totalpage : $page+1;
	$str = "<a href='page.php?page=1'>首页</a><a href='page.php?page=$pre'>上一页</a><a href='page.php?page=$next'>下一页</a><a href='page.php?page=$totalpage'>尾页</a>";

 ?>
 <!DOCTYPE html>
 <html lang="en">
 <head>
 	<meta charset="UTF-8">
 	<title>Document</title>
 </head>
 <body>
 	<center>
 		<table>
 			<tr>
 				<td>商品名</td>
 				<td>价格</td>
 				<td>数量</td>
 				<td>操作</td>
 			</tr>
 			<?php foreach ($data as $val ){?>
 				<tr>
 					<td><?php echo $val['name']?></td>
 					<td><?php echo $val['money']?></td>
					<td>100</td>
					<td><a href="detail.php?id=<?php echo $val['id']?>"><input type="button" value="详情"></a></td>
 				</tr>
 				<?php }?>
 		</table>
 		<?php echo $str;	?>
 	</center>
 </body>
 </html>